//$URL: http://dasding.googlecode.com/svn/branches/testzeugs/data/dao/mongoDB/src/main/java/de/piratech/dasding/data/database/mongo/EventCategoryDataImpl.java $
//$Id: EventCategoryDataImpl.java 90 2012-11-20 18:42:49Z amuthmann@gmail.com $
/*
 * Copyright 2012 Piratech.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.piratech.dasding.data.database.mongo;

import com.mongodb.DB;
import de.piratech.dasding.data.EventCategory;
import de.piratech.dasding.data.database.EventCategoryData;
import java.util.List;

/**
 */
public class EventCategoryDataImpl extends AbstractMongoDB<EventCategory> implements EventCategoryData {

  public EventCategoryDataImpl(DB pDB) {
    super(pDB, EventCategory.class, COLLECTIONS.EVENTCATEGORY_COLLECTION);
  }

  @Override
  public EventCategory createEventCategory(EventCategory pEventCategory) {
    return getDBCollection().insert(pEventCategory).getSavedObject();
  }

  @Override
  public EventCategory getEventCategory(String pId) {
    return getDBCollection().findOneById(pId);
  }

  @Override
  public void updateEventCategory(EventCategory pEventCategory) {
    getDBCollection().updateById(pEventCategory.getId(), pEventCategory);
  }

  @Override
  public void deleteEventCategory(EventCategory pEventCategory) {
    getDBCollection().removeById(pEventCategory.getId());
  }

  @Override
  public List<EventCategory> getCategories() {
    return getDBCollection().find().toArray();
  }

  @Override
  public List<EventCategory> getVerifiedCategories() {
    return findByVerified(true);
  }

  @Override
  public List<EventCategory> getNotVerifiedCategories() {
    return findByVerified(false);
  }

  public List<EventCategory> findByVerified(boolean pVerified) {
    return getDBCollection().find().is("verified", pVerified).toArray();
  }
}
